home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / wsc4c21.zip / SELFTEST.C < prev    next >
C/C++ Source or Header  |  1997-05-22  |  7KB  |  268 lines

  1. /*
  2. **  SELFTEST.C
  3. **
  4. **  Port test example program.
  5. */
  6.  
  7. #define USECOMM
  8.  
  9. #include <windows.h>
  10.  
  11. #ifdef WIN32
  12. #define USE_INS HINSTANCE
  13. #define USE_PTR PSTR
  14. #else
  15. #define USE_INS HANDLE
  16. #define USE_PTR LPSTR
  17. #endif
  18.  
  19. #include "selftest.h"
  20. #include "message.h"
  21. #include "wsc.h"
  22. #include "ascii.h"
  23. #include "paint.h"
  24. #include "line.h"
  25. #include "menu.h"
  26. #include "about.h"
  27. #include "runtest.h"
  28. #include "sioerror.h"
  29.  
  30. /* public globals */
  31.  
  32. HWND hMainWnd;            /* main window handle */
  33. HWND hInfoWnd;            /* popup handle */
  34. USE_INS hInstance;        /* program instance */
  35. int OnLineFlag = FALSE;   /* TRUE: online */
  36. int FatalFlag = FALSE;    /* TRUE: fatal error */
  37. char Temp[1024];
  38.  
  39. /* private globals */
  40.  
  41. static int WinWidth = 8 * NCOLS;
  42. static int WinHeight = 12 * NROWS + 48;
  43. static int ThePort = COM1;
  44. static int TheBaudRate = Baud19200;
  45. static char *BaudRateTable[5] = {"9600","19200","38400","57600",""};
  46.  
  47. /* miscellaneous functions */
  48.  
  49. void ErrorCheck(int);
  50. void ErrorMessage(char *);
  51. void SetTitle(void);
  52.  
  53. #ifdef WIN32
  54. int WINAPI
  55. #else
  56. int PASCAL
  57. #endif
  58. WinMain(USE_INS hInst,USE_INS hPrevInstance,USE_PTR lpCmdLine,int nCmdShow)
  59. {WNDCLASS  wc;
  60.  MSG msg;
  61.  BOOL Result;
  62.  if(!hPrevInstance)
  63.    {/* register main window class */
  64.     wc.style = CS_HREDRAW | CS_VREDRAW;
  65.     wc.lpfnWndProc = MainWndProc;
  66.     wc.cbClsExtra = 0;
  67.     wc.cbWndExtra = 0;
  68.     wc.hInstance = hInst;
  69.     wc.hIcon = LoadIcon(hInst, "SelftestIcon");
  70.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  71.     wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  72.     wc.lpszMenuName =  "SelftestMenu";
  73.     wc.lpszClassName = "SelftestWClass";
  74.     Result = RegisterClass(&wc);
  75.     if(!Result) return FALSE;
  76.    }
  77.  
  78.  /* create main window */
  79.  hInstance = hInst;
  80.  hMainWnd = CreateWindow(
  81.         "SelftestWClass", "Selftest",       WS_OVERLAPPEDWINDOW,
  82.         CW_USEDEFAULT,    CW_USEDEFAULT,
  83.         WinWidth,         WinHeight,
  84.         NULL,             NULL,
  85.         hInstance,        NULL);
  86.  ShowWindow(hMainWnd, nCmdShow);
  87.  UpdateWindow(hMainWnd);
  88.  
  89.  /* window control loop */
  90.  
  91.  while(GetMessage(&msg,NULL,0,0))
  92.    {
  93.     TranslateMessage(&msg);
  94.     DispatchMessage(&msg);
  95.    }
  96.  return (msg.wParam);
  97. } /* end WinMain */
  98.  
  99. #ifdef WIN32
  100. LRESULT CALLBACK
  101. #else
  102. long FAR PASCAL
  103. #endif
  104. MainWndProc(HWND hWindow,UINT iMsg,WPARAM wParam,LPARAM lParam)
  105. {int  Code;
  106.  HDC  hDC;
  107.  PAINTSTRUCT ps;
  108.  static FARPROC lpfnAboutDlgProc;
  109.  
  110.  hMainWnd = hWindow;
  111.  switch (iMsg)
  112.     {case WM_COMMAND:
  113.          switch(wParam)
  114.            {case MSG_ABOUT:
  115. #ifdef WIN32
  116.               DialogBox(hInstance,"AboutBox",hMainWnd,AboutDlgProc);
  117. #else
  118.               DialogBox(hInstance,"AboutBox",hMainWnd,lpfnAboutDlgProc);
  119. #endif
  120.               break;
  121.  
  122.             case MSG_DEBUG:
  123.               break;
  124.  
  125.             case MSG_INSTRUCT:
  126.               DisplayLine("SELFTEST tests a single port for functionality.\n");
  127.               DisplayLine("The port must terminate with a loopback adapter.");
  128.               DisplayLine("DTR/DSR are tested if DTR is wired to DSR, and");
  129.               DisplayLine("RTS/CTS are tested if RTS is wired to CTS.");
  130.               DisplayLine("See LOOPBACK.DOC for more info.\n");
  131.               break;
  132.  
  133.             case MSG_TEST:
  134.               Code = SioReset(ThePort,1024,1024);
  135.               if(Code<0)
  136.                 {SioError(Code,"SioReset");
  137.                  break;
  138.                 }
  139.               SioBaud(ThePort,TheBaudRate);
  140.               RunTest(ThePort);
  141.               SioDone(ThePort);
  142.               break;
  143.  
  144.             case MSG_COM1:
  145.               UncheckTheMenu(MSG_COM1+ThePort);
  146.               ThePort = COM1;
  147.               CheckTheMenu(MSG_COM1);
  148.               SetTitle();
  149.               break;
  150.  
  151.             case MSG_COM2:
  152.               UncheckTheMenu(MSG_COM1+ThePort);
  153.               ThePort = COM2;
  154.               CheckTheMenu(MSG_COM2);
  155.               SetTitle();
  156.               break;
  157.  
  158.             case MSG_COM3:
  159.               UncheckTheMenu(MSG_COM1+ThePort);
  160.               ThePort = COM3;
  161.               CheckTheMenu(MSG_COM3);
  162.               SetTitle();
  163.               break;
  164.  
  165.             case MSG_COM4:
  166.               UncheckTheMenu(MSG_COM1+ThePort);
  167.               ThePort = COM4;
  168.               CheckTheMenu(MSG_COM4);
  169.               SetTitle();
  170.               break;
  171.  
  172.             case MSG_9600:
  173.               UncheckTheMenu(MSG_9600+TheBaudRate-Baud9600);
  174.               TheBaudRate = Baud9600;
  175.               CheckTheMenu(MSG_9600);
  176.               SetTitle();
  177.               break;
  178.  
  179.             case MSG_19200:
  180.               UncheckTheMenu(MSG_9600+TheBaudRate-Baud9600);
  181.               TheBaudRate = Baud19200;
  182.               CheckTheMenu(MSG_19200);
  183.               SetTitle();
  184.               break;
  185.  
  186.             case MSG_38400:
  187.               UncheckTheMenu(MSG_9600+TheBaudRate-Baud9600);
  188.               TheBaudRate = Baud38400;
  189.               CheckTheMenu(MSG_38400);
  190.               SetTitle();
  191.               break;
  192.  
  193.             case MSG_57600:
  194.               UncheckTheMenu(MSG_9600+TheBaudRate-Baud9600);
  195.               TheBaudRate = Baud57600;
  196.               CheckTheMenu(MSG_57600);
  197.               SetTitle();
  198.               break;
  199.  
  200.             case MSG_EXIT:
  201.               PostQuitMessage(0);
  202.               break;
  203.  
  204.             default:
  205.               return (DefWindowProc(hMainWnd, iMsg, wParam, lParam));
  206.            }
  207.          break;
  208.  
  209.     case WM_CREATE:
  210.  
  211. #ifdef WIN32
  212. #else
  213.       /* create AboutDlgProc() thunk */
  214.       lpfnAboutDlgProc = MakeProcInstance(AboutDlgProc, hInstance);
  215. #endif
  216.       /* initialize paint module */
  217.       PaintInit();
  218.       /* COM1 @ 19200 is the default */
  219.       CheckTheMenu(MSG_COM1);
  220.       CheckTheMenu(MSG_9600+TheBaudRate-Baud9600);
  221.       SetTitle();
  222.       break;
  223.  
  224.     case WM_SETFOCUS:
  225.       /* create client area caret */
  226.       CreateCaret(hMainWnd,NULL,3,10);
  227.       SetCaretPos(PaintGetColPos(),PaintGetRowPos());
  228.       ShowCaret(hMainWnd);
  229.       ShowCaret(hMainWnd);
  230.       break;
  231.  
  232.     case WM_KILLFOCUS:
  233.       DestroyCaret();
  234.       break;
  235.  
  236.     case WM_PAINT:
  237.       HideCaret(hMainWnd);
  238.       hDC = BeginPaint(hMainWnd, &ps);
  239.       SetMapMode(hDC,MM_ANISOTROPIC);
  240.       SelectObject(hDC, GetStockObject(OEM_FIXED_FONT) );
  241.       PaintMain(hDC,&ps);
  242.       EndPaint(hMainWnd,&ps);
  243.       SetCaretPos(PaintGetColPos(),PaintGetRowPos());
  244.       ShowCaret(hMainWnd);
  245.       break;
  246.  
  247.     case WM_DESTROY:
  248.       PostQuitMessage(0);
  249.       break;
  250.  
  251.     default:
  252.       return (DefWindowProc(hMainWnd, iMsg, wParam, lParam));
  253.    }
  254.  return 0;
  255. } /* end MainWndProc */
  256.  
  257. void ErrorMessage(char *MsgPtr)
  258. {
  259.  MessageBox(hMainWnd,MsgPtr,"ERROR",MB_ICONEXCLAMATION | MB_OK);
  260. }
  261.  
  262. void SetTitle(void)
  263. {wsprintf((LPSTR)Temp,"SELFTEST: COM%d @ %s",
  264.     1+ThePort, BaudRateTable[TheBaudRate-Baud9600]);
  265.  SetWindowText(hMainWnd,Temp);
  266.  DrawMenuBar(hMainWnd);
  267. }
  268.